package artid.com.arttogo.adapter;

import java.util.ArrayList;
import java.util.List;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.view.ViewGroup;
import artid.com.arttogo.activity.MallDetailsActivity;
import artid.com.arttogo.bean.GoodsList;

/**
 * ClassName:MatchFragmentAdapter <br/>
 * Function: 项目页适配器<br/>
 * Reason: 解决项目页标签可以左右滑动的功能 <br/>
 * Date: 2014-2-25 下午4:00:34 <br/>
 *
 * @author ybq
 * @version
 * @since JDK 1.6
 * @see
 */
public class MallDetFragmentAdapter extends FragmentStatePagerAdapter {

    private List<GoodsList> mList;
    private List<MallDetailsActivity> fragList;


    public MallDetFragmentAdapter(FragmentManager fm) {
        super(fm);
        fragList = new ArrayList<MallDetailsActivity>();
    }

    public void setData(List<GoodsList> list) {
        mList = list;
        notifyDataSetChanged();
    }


    @Override
    public MallDetailsActivity getItem(int position) {
        return getFragments(position);
    }


    @Override
    public Object instantiateItem(ViewGroup group, int position) {
        return super.instantiateItem(group, position);
    }

    private MallDetailsActivity getFragments(int position) {

        MallDetailsActivity fragment = new MallDetailsActivity();
        fragment.setArguments(getBundle(position));
        fragList.add(fragment);
        // return fragment;
        return fragment;
    }

    private Bundle getBundle(int position) {
        Bundle bundle = new Bundle();
        String id = "";

        GoodsList data = mList.get(position);
        id = data.getGoods_id();
        bundle.putString("id", id);
        return bundle;
    }

    @Override
    public int getCount() {

        return null == mList ? 0 : mList.size();
    }

    @Override
    public int getItemPosition(Object object) {
        return POSITION_NONE;
    }
}
